/**
 iTextUploader
 (C) 2008 Asgl (myselftdev@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* Revision: $Id: PreferencesData.m 25 2008-09-03 17:33:20Z myselftdev $ */

#import "PreferencesData.h"

@implementation PreferencesData

- (id)init
{
	if (self = [super init])
	{
		NSLog(@"Data file: %@", [@DATA_FILE stringByExpandingTildeInPath]);
		
		dataDict = [ [NSMutableDictionary alloc] initWithContentsOfFile:[@DATA_FILE stringByExpandingTildeInPath]];
		if(dataDict == nil)
		{
			[dataDict release];
			
			dataDict = [ [NSMutableDictionary alloc] initWithCapacity:3];
			[dataDict setObject:@"" forKey:@"username"];
			[dataDict setObject:@"" forKey:@"password"];
			[dataDict setObject:[NSNumber numberWithInt:0] forKey:@"lastupload"];
			[dataDict writeToFile:[@DATA_FILE stringByExpandingTildeInPath] atomically:YES];
		}
	}
	return self;
}

- (id)getData:(NSString*)name
{
	return [dataDict objectForKey:name];
}

- (BOOL)setValue:(id)value forData:(NSString*)name
{
	if(![name isEqualToString:@"lastupload"])
	{
		[dataDict setObject:[NSNumber numberWithInt:0] forKey:@"lastupload"];
	}
	
	[dataDict setValue:value forKey:name];
	
	[dataDict writeToFile:[@DATA_FILE stringByExpandingTildeInPath] atomically:YES];
	
	return YES;
}

-(void)dealloc
{
	[dataDict release];
	[super dealloc];
}

@end
